//
//  WeSellerMessageCell.m
//  WeGalaxy
//
//  Created by Zheng on 2017/7/24.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "WeSellerMessageCell.h"
#import "WeSellerMessageModel.h"
#import "WeSellerMessageLabel.h"

@implementation WeSellerMessageCell

- (void)setModel:(WeSellerMessageModel *)model {
    _model = model;
    
    _dateLbl.text = _model.timestamp;
    
    [_dateLbl mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self).multipliedBy(0.4);
        make.centerX.equalTo(self);
        make.bottom.mas_equalTo(-20);
        make.height.mas_equalTo(16);
    }];
    
    if (model.chartType.integerValue != 3) {
        
        _iconImgv.hidden = NO;
        _msgLbl.hidden = NO;
        _orderLbl.hidden = YES;
        
        if (model.chartType.integerValue == 1) {
            
            [_iconImgv mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(15);
                make.top.mas_equalTo(10);
                make.width.height.mas_equalTo(40);
            }];
            
//            _msgLbl.textAlignment = NSTextAlignmentLeft;
            _msgLbl.layer.backgroundColor = [[UIColor whiteColor] CGColor];
            
        } else  {
            
            [_iconImgv mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-15);
                make.top.mas_equalTo(10);
                make.width.height.mas_equalTo(40);
            }];
            
//            _msgLbl.textAlignment = NSTextAlignmentRight;
            _msgLbl.layer.backgroundColor = [kRGB_COLOR(245, 66, 54, 1) CGColor];
        }

        [_msgLbl mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(70);
            make.right.mas_equalTo(-70);
            make.top.mas_equalTo(15);
            make.bottom.equalTo(_dateLbl.mas_top).offset(-20);
        }];
        
        [_iconImgv sd_setImageWithURL:[NSURL URLWithString:_model.userUrl]];
        
        NSInteger row = [_model.chatContent length]/116+1;
        
        NSString *str = @"";
        
        for (int i = 0; i < row; i++) {
            str = [str stringByAppendingString:@"\n"];
        }
                
        _msgLbl.text = [NSString stringWithFormat:@"\n%@%@",_model.chatContent,str];

    } else {
        _iconImgv.hidden = YES;
        _msgLbl.hidden = YES;
        _orderLbl.hidden = NO;
        
        _orderLbl.text = [NSString stringWithFormat:@"\n\n%@\n\n[订单]买家已拍下,等待买家付款\n\n",_model.notifactionTitle];
    }
    
    
    
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _iconImgv.layer.cornerRadius = 20;
    _iconImgv.layer.borderWidth = 1;
    _iconImgv.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    _iconImgv.layer.masksToBounds = YES;
    _iconImgv.hidden = YES;
    
    _dateLbl.layer.cornerRadius = 8;
    _dateLbl.layer.masksToBounds = YES;

    _msgLbl.layer.cornerRadius = 8;
    _msgLbl.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    _msgLbl.layer.borderWidth = 1;
    _msgLbl.layer.masksToBounds = YES;
    _msgLbl.hidden = YES;
    _msgLbl.width = 15;
    
    _orderLbl.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    _orderLbl.layer.borderWidth = 1;
    _orderLbl.hidden = YES;
    _orderLbl.width = 30;
    _orderLbl.textColor = [UIColor lightGrayColor];

    [_orderLbl mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(5);
        make.bottom.equalTo(_dateLbl.mas_top).offset(-20);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
